<%@ page contentType="text/html; charset=UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="nst" uri="http://www.nstechs.com/app/core"%>
<%@ page isELIgnored="false"%>

<script>
	var rootPath = "${pageContext.request.contextPath}";
	$(document).ready(function() {

		$('.back').click(function() {
			window.location = rootPath + "/navigation/tree";
		});

		$("#Name").blur(function() {
			var name = $("#Name").val().trim();
			var desc = $("#Description").val().trim();
			if (name == "") {
				$(".name-valid").html(" * name is needed");
			} else {
				$(".name-valid").html("");
			}
		});

		$("#Description").blur(function() {
			var desc = $("#Description").val().trim();
			if (desc == "") {
				$(".desc-valid").html(" * description is needed");
			} else {
				$(".desc-valid").html("");
			}
		});

		$("#Url").blur(function() {
			var desc = $("#Url").val().trim();
			if (desc == "") {
				$(".url-valid").html(" * url is needed");
			} else {
				$(".url-valid").html("");
			}
		});

		$(".modify").click(function() {
			var name = $("#Name").val().trim();
			var desc = $("#Description").val().trim();
			var url = $("#Url").val().trim();
			if (name == "") {
				$(".name-valid").html(" * name is needed");
				$("#Name").focus();
				return;
			}
			if (desc == "") {
				$(".desc-valid").html(" * description is needed");
				return;
			}
			if (url == "") {
				$(".url-valid").html(" * url is needed");
				return;
			}
			$(".name-valid").html("");
			$(".desc-valid").html("");
			if (desc != "" && name != "") {
				$("#navigationForm").submit();
			}
		});
	});
</script>


<div id="main">
	<div class="content">
		<c:choose>
			<c:when test="${nav==null}">
				<h2>Add Navigation</h2>
			</c:when>
			<c:otherwise>
				<h2>Modify Navigation</h2>
			</c:otherwise>
		</c:choose>
		<form 
		      <c:choose>
	            <c:when test="${nav==null}">
	              method="post"
	            </c:when>
	            <c:otherwise>
	               method="put"
	            </c:otherwise>
	         </c:choose>
		  method="post" id="navigationForm" action="navigation">
			<ul>
				<li><label for="Name">navigation Name<span
						class="required">*</span> </label> <input id="Name" name="name"
					type="text" value="${nav.name}"> <span class="name-valid" style="color:red;"></span>
				</li>

				<li><label for="url">link url<span class="required">*</span>
				</label> <input id="Url" name="url" type="text" value="${nav.url}"> <span
					class="url-valid" style="color:red;"></span>
				</li>

			   <li><label for="orderList">order</label> <input
						type="text" id="orderList"  name="orderList" value="${nav.orderList}"/>
					<span class="order-valid" style="color:red;"></span>
				</li>

				<li><label for="description">description</label> <textarea
						id="Description" cols="20" rows="2" name="description">${nav.description}</textarea>
					<span class="desc-valid" style="color:red;"></span>
				</li>
				<li class="btnline"><input class="modify" value="Modify"
					type="button"> &nbsp; <input class="back" value="back list"
					type="button">
				</li>
			</ul>
		</form>
	</div>
</div>